<?php
declare (strict_types = 1);

namespace app\adminapi\controller;

use adminmatrix\annotation\auth\IsPermission;
use adminmatrix\server\app\server\JsonService;
use app\adminapi\logic\LoginLogic;
use think\exception\HttpException;
use think\Request;
use adminmatrix\server\app\adminMatrix;
class LoginController extends AdminMatrix
{
    public array $notNeedLogin = ['index' , 'logout'];
    #[IsPermission]
    public function index(Request $request , LoginLogic $logic)
    {
        try {
            $admin = $logic->login($request);
            return JsonService::success('登录成功' , $admin);
        } catch (HttpException $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }

    #[IsPermission]
    public function logout( Request $request ,  LoginLogic $logic)
    {
        try {
            $logic->logout($request->adminInfo);
            return JsonService::success('退出成功');
        } catch (HttpException $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }
}
